<?php
	require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php");
	gatekeeper();
	
	$chatsession = get_input("chatsession");
	$chatmessage = nl2br(get_input("chatmessage"));
	$senderid = get_input("senderid");
	
	$maxmembers = get_entities_from_relationship("elggchat_session_member", $chatsession, null, null, null, null, null, null, null, true);
	$members = get_entities_from_relationship("elggchat_session_member", $chatsession, null, null, null, null, null, $maxmembers);

	if(!empty($chatmessage) && is_member($senderid, $members)){
		$chat_session_object = get_entity($chatsession);
		$chat_session_object->annotate("elggchat_message", $chatmessage,ACCESS_LOGGED_IN,$senderid);
	}
	exit();
?>